<script setup lang='ts'>
import { ref } from 'vue';
import { getTextset, modifyText } from '@/api/axios/platformAxios';

const tableData = ref([])


// 初始化文本
function initText() {
    getTextset().then(res => {
        tableData.value = res.rows
        console.log(res.rows);
    })
}
initText()

//对话框
const dialogVisible = ref(false)
let titleInput = ref('')
let content = ref('')

const textData = ref({
    id:"",
    code: '',
    content: '',
    status: '',
    title: '',
})


// 编辑按钮
function edit(data) {
    dialogVisible.value = true
    // console.log(data);
    textData.value.title = data.title
    textData.value.content = data.content
    textData.value.id = data.id
}

import { ElMessage } from 'element-plus'

// 保存按钮
function saveText() {
    modifyText(textData.value).then(res => {
        // console.log(res);
        ElMessage({
            showClose: true,
            message: res.msg,
            type: 'success',
        })
        initText()
    })
    dialogVisible.value = false
}

</script>

<template>
    <div>
        <el-table :data="tableData" style="width: 95%;margin: 20px auto" border='true' >
            <el-table-column fixed type='index' index='index' label="序号" width='180' align='center'/>
            <el-table-column prop="title" label="名称" align='center' />
            <el-table-column prop="createTime" label="更新时间" width='200' align='center'/>
            <el-table-column fixed="right" label="操作" width="300" align='center'>
                <template v-slot='scope'>
                    <el-button link type="primary" style='font-size: 13px' @click='edit(scope.row)'>编辑</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
    <div>
        <el-dialog
            v-model="dialogVisible"
            title=""
            width="912"
        >
            <div style='width: 100%;text-align: center'>
                <input
                    v-model="textData.title"
                    class='titleInput'
                    size="large"
                />
            </div>
            <div>
                <Editor v-model='textData.content' style='height: 250px;margin: 40px auto'></Editor>
            </div>
            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="dialogVisible = false">取消</el-button>
                    <el-button type="primary" @click="saveText">
                        保存
                    </el-button>
                </div>
            </template>
        </el-dialog>
    </div>
</template>

<style lang='scss'>
.gap-4 {
    padding: 26px 25px;
    width: 100%;
    margin-left: 20px;
}
div.cell{
    height: 30px;
    font-size: 14px;
    line-height: 30px;
    padding: 9px 0 !important;
}
.dialog-footer {
    display: flex;
    justify-content: center;
}
.titleInput{
    width: 240px;
    border: none;
    text-align: center;
    font-size: 30px;
}
</style>
